'''
import fitter 
import pandas as pd 
import numpy as np
import os

def read_data(url, file_url):
    data = pd.read_csv(file_url + url,encoding= "utf-8", 
                    converters={"预起":pd.to_datetime,
                                "预起变更":pd.to_datetime,
                                "离地":pd.to_datetime,
                                "预达":pd.to_datetime,
                                "预达变更":pd.to_datetime,
                                "落地":pd.to_datetime})
    return data 

def fit_data(data):
    f = fitter.Fitter(data)
    f.fit()
    f.summary() 


if __name__ == "__main__":
    file_url = "data\\clean\\"
    os_list = os.listdir(file_url)
    # 读取数据
    total_data = read_data(file_url = "data\\clean\\",url = "2021-06-01.csv")

    # 获取所有的数据
    for file in os_list[1:]:
        new_data = read_data(file,file_url)
        total_data = total_data.append(new_data)
        total_data.index = [i for i in range(total_data.shape[0])]
    # print(total_data.shape)
    # print(total_data.head())

    raw_data = total_data["误差"].dropna()
    print(raw_data)
    # print(fitted_data)
    # print(type(fitted_data.values))

    fit_data(raw_data)
'''


import builtins
import fitter 
import pandas as pd 
import numpy as np
import os

def read_data(url, file_url):
    data = pd.read_csv(file_url + url,encoding= "utf-8", 
                    converters={"预起":pd.to_datetime,
                                "预起变更":pd.to_datetime,
                                "离地":pd.to_datetime,
                                "预达":pd.to_datetime,
                                "预达变更":pd.to_datetime,
                                "落地":pd.to_datetime})
    return data 



if __name__ == "__main__":
    file_url = "data\\clean\\"
    os_list = os.listdir(file_url)
    # 读取数据
    total_data = read_data(file_url = "data\\clean\\",url = "2021-06-01.csv")

    # 获取所有的数据
    for file in os_list[1:]:
        new_data = read_data(file,file_url)
        total_data = total_data.append(new_data)
        total_data.index = [i for i in range(total_data.shape[0])]
    # print(total_data.shape)
    # print(total_data.head())

    raw_data = total_data["误差"].dropna()
    print(raw_data.head())
    # print(fitted_data)
    # print(type(fitted_data.values))

    # 开始拟合
    f = fitter.Fitter(raw_data, bins= 1000, xmax = 450, xmin = -300)
    f.fit()
    print(f.get_best())
    print(f.summary())
    
